// 基础路由

import type { AppRouteRecordRaw } from '@/router/types';
import { isArray } from '@/utils/is';
import * as APP_ROUTE from './app';

const LAYOUT = (() => import('@/layout/layout.vue'))

let APP_ROUTES: AppRouteRecordRaw[] = []


const objBasic: any = APP_ROUTE
let key: string

for ( key in objBasic) {
  const MODULE = objBasic[key] as AppRouteRecordRaw
  APP_ROUTES.push(MODULE)
}

/**
 * 匹配父级路由
 * @param routes 子集路由
 * @param name 父级路由名
 * @returns 
 */
const handlerChildrenComp = (routes: AppRouteRecordRaw[],name: string) => {
  return isArray(routes) && routes.filter((e) => {
    return e.parent === name
  })
}

export const LOGIN_ROUTE: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('@/views/example/login.vue'),
  meta: {
    title: '登录',
    hideMenu: true
  },
 }
export const HOME_ROUTE: AppRouteRecordRaw = {
  path: '/',
  name: 'Home',
  component: LAYOUT,
  meta: {
    sort: 1,
    title: '首页',
    hideMenu: true
  },
 }

export const COMMON_ROUTE: AppRouteRecordRaw = {

    path: '/components',
    name: 'Components',
    component: LAYOUT,
    meta: {
      sort: 2,
      title: '公用组件',
    },
}

export const SYSTEM_ROUTE: AppRouteRecordRaw = {

  path: '/system',
  name: 'System',
  meta: {
    title: '系统管理',
    sort: 99
  }
} 

export const REDIRECT_ROUTE: AppRouteRecordRaw = {
  path: '/redirect',
  component: () => import('@/views/example/403.vue'),
  name: 'RedirectTo',
  meta: {
    sort: 3,
    title: "Redirect",
    hideBreadcrumb: true,
    hideMenu: true,
  }
};

export const ERROR_LOG_ROUTE: AppRouteRecordRaw = {
  path: '/error-log',
  name: 'ErrorLog',
  component: () => import('@/views/example/403.vue'),
  redirect: '/error-log/list',
  meta: {
    sort: 4,
    title: 'ErrorLog',
    hideMenu: true,
    hideBreadcrumb: true,
    hideChildrenInMenu: true,
  }
};

// 404 on a page

export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
  path: '/:path(.*)*',
  name: "PageNotFound",
  component: () => import('@/views/example/404.vue'),
  meta: {
    sort: 2,
    title: '404 ErrorPage',
    hideBreadcrumb: true,
    hideMenu: true,
  }
};
